// Author: wsfuyibing <682805@qq.com>
// Date: 2025-05-15

package daily

import (
	"context"
	"gitee.com/go-libs/result"
	"gitee.com/go-wares/framework-iris/framework/src/logics"
	"github.com/kataras/iris/v12"
	"server/app/http/models"
	"server/app/lib"
)

// Logic
// 加载用户资料.
type Logic struct {
	admin    *models.ArcadeAdmins
	response *Response
}

// New
// 创建逻辑实例.
func New() logics.Logical {
	return &Logic{
		response: NewResponse(),
	}
}

// Before
// 前置校验.
func (o *Logic) Before(_ context.Context, i iris.Context) (err error) {
	o.admin = lib.Arcade.GetMaster().GetAdmin(i)
	return
}

// Run
// 执行逻辑.
func (o *Logic) Run(ctx context.Context, _ iris.Context) result.Result {
	var (
		calendar *models.ArcadeCalendar
		err      error
		res      = result.New()
	)

	// 1. 初始化日历.
	if calendar, err = lib.Arcade.GetMaster().InitCalendar(ctx, o.admin.ArcadeId); err != nil {
		return res.WithError(err)
	}

	// 2. 输出结果.
	o.response.WithCalendar(calendar)
	return res.With(o.response)
}
